package my.jieh.tips.math;

/**
 * <p>Title: Core Java Technologies Tech Tips</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: Blueimp</p>
 * @author jieh
 * @version 1.0
 */
import java.math.BigInteger;
import java.util.Random;

public class PrimeDemo3 {
	public static void main(String args[]) {
		for (int numBits = 100;
				 numBits <= 300; numBits += 100) {
			generatePrimes(100, numBits);
		}
	}

	static Random rnd = new Random();

	// Generate numPrimes probable primes
	// of numBits length.

	static void generatePrimes(
			int numPrimes, int numBits) {
		long start = System.currentTimeMillis();
		for (int i = 1; i <= numPrimes; i++) {
			BigInteger.probablePrime(numBits, rnd);
		}
		long elapsed =
				System.currentTimeMillis() - start;
		System.out.println(
				"ms to generate " + numBits
		+ " bit prime  = "
	+ (elapsed / numPrimes));
	}
}